package iut.acy.retard;



import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends Activity implements OnClickListener {
	public static final String PREFS_NAME = "retards_info_preferences";
	public static SharedPreferences preferences;
	public static SharedPreferences.Editor editor;
	
	private EditText nom;
	private EditText prenom;
	private EditText heure;
	private EditText duree;
	private EditText taf;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		preferences = getSharedPreferences(PREFS_NAME, 0);
		editor = preferences.edit();
		
		Button submit = (Button)findViewById(R.id.post);
		
		this.nom = (EditText)findViewById(R.id.editTextNom);
		this.nom.setText(preferences.getString("nom", ""));
		this.nom.addTextChangedListener(new TextWatcher(){
			@Override
			public void afterTextChanged(Editable s) {
				editor.putString("nom", s.toString());
				editor.commit();
			}
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {}

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {}
		});
		
		this.prenom = (EditText)findViewById(R.id.editTextPrenom);
		this.prenom.setText(preferences.getString("prenom", ""));
		this.prenom.addTextChangedListener(new TextWatcher(){
			@Override
			public void afterTextChanged(Editable s) {
				editor.putString("prenom", s.toString());
				editor.commit();
			}
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {}

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {}
		});
		
		this.heure = (EditText)findViewById(R.id.editTextHeureCours);
		this.duree = (EditText)findViewById(R.id.editTextDureeRetard);
		this.taf = (EditText)findViewById(R.id.editTextTravail);
		
		submit.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	public void onClick(View v){
		switch(v.getId()){
		case R.id.post :
			ConfirmDialog cd = new ConfirmDialog(this);
			break;
		default : 
			break;
		}
		
	}

	public EditText getNom() {
		return nom;
	}

	public void setNom(EditText nom) {
		this.nom = nom;
	}

	public EditText getPrenom() {
		return prenom;
	}

	public void setPrenom(EditText prenom) {
		this.prenom = prenom;
	}

	public EditText getHeure() {
		return heure;
	}

	public void setHeure(EditText heure) {
		this.heure = heure;
	}

	public EditText getDuree() {
		return duree;
	}

	public void setDuree(EditText duree) {
		this.duree = duree;
	}

	public EditText getTaf() {
		return taf;
	}

	public void setTaf(EditText taf) {
		this.taf = taf;
	}
	
	
}
